package com.edu.exam.enums;

/**
 * 检测状态枚举
 * 
 * @author S-01 Module Designer
 * @version 2.0
 * @since 2025-11-10
 */
public enum DetectionStatus {
    PENDING("pending", "待检测"),
    DETECTED("detected", "已检测"),
    IN_PROGRESS("in_progress", "处理中"),
    RESOLVED("resolved", "已解决"),
    IGNORED("ignored", "已忽略"),
    FAILED("failed", "检测失败");

    private final String code;
    private final String description;

    DetectionStatus(String code, String description) {
        this.code = code;
        this.description = description;
    }

    public String getCode() {
        return code;
    }

    public String getDescription() {
        return description;
    }

    /**
     * 从代码创建枚举实例
     *
     * @param code 枚举代码
     * @return 对应的枚举实例
     * @throws IllegalArgumentException 如果代码无效
     */
    public static DetectionStatus fromCode(String code) {
        if (code == null || code.trim().isEmpty()) {
            throw new IllegalArgumentException("代码不能为空");
        }
        for (DetectionStatus status : values()) {
            if (status.getCode().equals(code)) {
                return status;
            }
        }
        throw new IllegalArgumentException("未知的检测状态代码: " + code);
    }

    /**
     * 从描述创建枚举实例
     *
     * @param description 枚举描述
     * @return 对应的枚举实例
     * @throws IllegalArgumentException 如果描述无效
     */
    public static DetectionStatus fromDescription(String description) {
        if (description == null || description.trim().isEmpty()) {
            throw new IllegalArgumentException("描述不能为空");
        }
        for (DetectionStatus status : values()) {
            if (status.getDescription().equals(description)) {
                return status;
            }
        }
        throw new IllegalArgumentException("未知的检测状态描述: " + description);
    }

    @Override
    public String toString() {
        return description;
    }
}